package org.dromara.system.controller.talent;


import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SubmitServiceRequestBo;
import org.dromara.system.domain.bo.WeChatCodeBo;
import org.dromara.system.domain.bo.WechatQueryRequestBo;
import org.dromara.system.domain.vo.WechatTalentUserVo;
import org.dromara.system.service.IServiceItemRecordService;
import org.dromara.system.service.ITalentUserService;
import org.dromara.system.service.WechatService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/talent/wechat")
public class WechatController extends BaseController {

    private final ITalentUserService talentUserService;

    private final IServiceItemRecordService serviceItemRecordService;

    private final WechatService wechatService;


    /**
     * 微信小程序查询人才信息
     */
    @PostMapping("/queryTalent")
    public R<WechatTalentUserVo> getTalentUser(@RequestBody WechatQueryRequestBo bo) {
        return R.ok(talentUserService.queryTalentForWechat(bo));
    }


    @PostMapping("/submitService")
    public R<Void> submitService(@RequestBody SubmitServiceRequestBo bo) {
        serviceItemRecordService.submitService(bo);
        return R.ok();
    }


    @PostMapping("/login")
    public R<String> loginWithWeChat(@RequestBody WeChatCodeBo weChatCodeBo) {
        String loginWithWeChat = wechatService.loginWithWeChat(weChatCodeBo.getXcxCode());

        return R.ok(loginWithWeChat);
    }


}
